package com.cruise.system.userhandle.controller;


import com.cruise.common.web.result.Result;
import com.cruise.common.web.util.WebUtils;
import com.cruise.system.userapi.dto.UpdateUserDTO;
import com.cruise.system.userapi.entity.SysUser;
import com.cruise.system.userapi.vo.GetUserInfoVO;
import com.cruise.system.userhandle.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cruise
 * @since 2021-03-31
 */
@Api(tags = "用户信息接口")
@RestController
@RequestMapping("/sysuser")
public class SysUserController {


    @Resource
    private SysUserService sysUserService;

    @PostMapping("/updateSysUser")
    @ApiOperation("跟新用户信息")
    public Result updateSysUser(@RequestBody UpdateUserDTO updateSysUser){
        SysUser sysUser = new SysUser();
        BeanUtils.copyProperties(updateSysUser, sysUser);
        sysUserService.updateSysUser(sysUser);
        return  Result.success();
    }

    @PostMapping("/getUserInfo")
    @ApiOperation("我的首页用户信息")
    public Result getUserInfo(){

        String userId = WebUtils.getUserId();
        GetUserInfoVO getUserInfoVo = sysUserService.getUserInfo(userId);
        return  Result.success(getUserInfoVo);
    }
}

